package com.kingwang.training.designpattern.command;

import com.kingwang.training.designpattern.command.bo.CloseCourseVideoCommand;
import com.kingwang.training.designpattern.command.bo.CourseVideo;
import com.kingwang.training.designpattern.command.bo.OpenCourseVideoCommand;
import com.kingwang.training.designpattern.command.bo.Staff;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CommandApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(CommandApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        //命令接收者
        CourseVideo courseVideo = new CourseVideo("设计模式");

        //创建命令
        OpenCourseVideoCommand openCourseVideoCommand = new OpenCourseVideoCommand(courseVideo);
        CloseCourseVideoCommand closeCourseVideoCommand = new CloseCourseVideoCommand(courseVideo);

        //创建执行人
        Staff staff = new Staff();

        //添加命令
        staff.addCommand(openCourseVideoCommand);
        staff.addCommand(closeCourseVideoCommand);

        //执行
        staff.execute();
    }
}
